Skip to content

Fix equals nullability annotations for jspecify compliance#18930

Open
therepanic wants to merge 1 commit intospring-projects:mainfrom
therepanic:jspecify-nullable-on-equals
Open

Fix equals nullability annotations for jspecify compliance#18930
therepanic wants to merge 1 commit intospring-projects:mainfrom
therepanic:jspecify-nullable-on-equals

Conversation

@therepanic
Copy link
Contributor

In this commit, we added @Nullable to equals methods of classes that support jspecify for consistency with other Spring projects and to avoid bugs that caused other Spring projects to do this natively.

Closes: gh-18929

In this commit, we added `@Nullable` to equals methods of classes that
support `jspecify` for consistency with other Spring projects and to
avoid bugs that caused other Spring projects to do this natively.

Closes: spring-projectsgh-18929

Signed-off-by: Andrey Litvitski <andrey1010102008@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 18, 2026
Comment on lines +106 to +107
if (obj == null) {
return false;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In some places this is necessary, otherwise the project will not build.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this one could also be addressed by fixing the unsafe type check that follows it. I'd recommend it just after the super.equals(obj) clause.

Copy link
Contributor

@jzheaux jzheaux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @therepanic, for the PR and the underlying research that went into it.

Does this also close #18927? If so, you may consider adding that Closes to your commit as well. Otherwise, will you please elaborate on that ticket what work is needed in addition to this PR?

@Override
public boolean equals(Object other) {
public boolean equals(@Nullable Object other) {
if (other == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one feels odd since I would imagine it best caught by a type check.

Can we remove this and also the unsafe type check by doing:

if (!(other instanceof DefaultCacheKey otherKey)) {
    return false;
}

Comment on lines +106 to +107
if (obj == null) {
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this one could also be addressed by fixing the unsafe type check that follows it. I'd recommend it just after the super.equals(obj) clause.

@jzheaux jzheaux self-assigned this Mar 21, 2026
@jzheaux jzheaux added in: core An issue in spring-security-core type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 21, 2026
@jzheaux jzheaux added this to the 7.1.0-RC1 milestone Mar 21, 2026
@jzheaux jzheaux added the status: waiting-for-feedback We need additional information before we can continue label Mar 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: core An issue in spring-security-core status: waiting-for-feedback We need additional information before we can continue type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

All equals methods with jspecify support must have a Nullable argument

3 participants